<%--
Created by IntelliJ IDEA.
User: 沐白
Date: 2020/8/15
Time: 10:47
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>商品消费</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/toastr/toastr.min.css"/>
    <script src="${pageContext.request.contextPath}/static/js/jquery-2.1.0.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/toastr/toastr.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/js/Myjs.js" type="text/javascript" charset="utf-8"></script>
    <style type="text/css">
        .table > tbody > tr > td {
            vertical-align: middle;
        }
        #spxinxi{
            font-size: 3px;
        }
    </style>
</head>

<body>
<%--<!-- 全局盒子 -->--%>
<div class="form-inline">
    <%--    <!-- 左边盒子 -->--%>
    <div class="form-group col-sm-4">
        <%--        <!-- 左边布局 -->--%>
        <table class="table table-bordered table-striped">
            <%--            <!-- 左边上部布局 -->--%>
            <tr>
                <td>
                    <div class="form-group-sm text-center">
                        商品列表
                    </div>
                </td>
            </tr>
            <%--            <!-- 左边中部布局 -->--%>
            <tr>
                <td>
                    <div class="form-group col-sm-12">
                        <table class="table table-striped table-bordered table-hover text-center">
                            <tr>
                                <td class="col-sm-3 text-center" style="vertical-align: middle; font-size: 12px;">商品编号
                                </td>
                                <td>
                                    <input type="text" class="form-control" id="shopid" placeholder="商品编号"/>
                                </td>
                            </tr>
                            <tr>
                                <td>商品名称</td>
                                <td>
                                    <input type="text" class="form-control" id="shopname" placeholder="商品名称"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="button" id="shoubtn" class="btn btn-primary btn-sm" value="搜索"/>
                                </td>
                                <td></td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
            <%--            <!-- 左边下部布局 -->--%>
            <tr>
                <td>
                    <div class="form-group col-sm-12">
                        <table id="spxinxi" class="table table-hover table-bordered table-striped text-center">
                            <tr>
                                <th>商品编号</th>
                                <th>商品名称</th>
                                <th>商品数量</th>
                                <th>商品类型</th>
                                <th>单位</th>
                                <th>价格</th>
                            </tr>
                            <tbody id="sptb">
                            </tbody>
                        </table>
                    </div>
                    <div class="form-inline">
                        <label>显示第 <span id="rowstartsp"></span>到第<span id="rowendsp"></span>条记录,总共<span
                                id="rowcountsp"></span>条记录,每页显示
                            <select class="form-control" id="pageSize">
                                <option selected="">5</option>
                                <option>10</option>
                                <option>20</option>
                                <option>50</option>
                                <option>100</option>
                            </select>
                            条记录</label>
                    </div>
                    <div class="form-group pull-right">
                        <div class="btn-group text-right">
                            <a href="javascript:search(pageBean.pageNo-1)" class="btn btn-default"><</a>
                            <div class="btn-group" id="btnsp"></div>
                            <a href="javascript:search(pageBean.pageNo+1)" class="btn btn-default">></a>
                        </div>
                    </div>
                </td>
            </tr>
            <%--            <!-- 左边布局结束 -->--%>
        </table>
        <%--        <!-- 左边盒子结束 -->--%>
    </div>
    <%--    <!-- 右边盒子 -->--%>
    <div class="form-group col-sm-8">
        <%--        <!-- 右边上边的盒子 -->--%>
        <div class="form-group col-sm-12">
            <table class="table table-striped table-bordered table-hover text-center">
                <thead>
                <tr>
                    <td colspan="4">
                        <div class="form-group-sm text-center">
                            会员信息
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align: middle;">会员查找</td>
                    <td colspan="3">
                        <div class="form-inline">
                            <div class="form-group col-sm-1">
                                <input type="text" class="form-control" id="huiId" placeholder="会员卡ID"/>
                            </div>
                            <div class="form-group col-sm-offset-1">
                                <input type="button" class="btn btn-danger btn-sm" onclick="duka()" value="读卡"/>
                                <input type="button" class="btn btn-info btn-sm" onclick="chongzhi()" value="重置"/>
                                <input type="button" class="btn btn-primary btn-sm" data-toggle="modal"
                                       data-target="#hyxq" value="会员详情"/>
                            </div>
                        </div>
                    </td>
                </tr>
                </thead>
                <tbody id="hyxxquan">
                <tr>
                    <td class="col-sm-2">会员ID</td>
                    <td class="col-sm-3 xyxx"></td>
                    <td class="col-sm-4">会员姓名</td>
                    <td class="col-sm-3 xyxx"></td>
                </tr>
                <tr>
                    <td>会员卡ID</td>
                    <td class="xyxx"></td>
                    <td>会员卡余额</td>
                    <td class="xyxx"></td>
                </tr>
                <tr>
                    <td>会员等级</td>
                    <td class="xyxx"></td>
                    <td>会员积分</td>
                    <td class="xyxx"></td>
                </tr>
                </tbody>
            </table>
            <%--            <!-- 右边上边的盒子结束 -->--%>
        </div>
        <%--        <!-- 右边中部的盒子 -->--%>
        <div class="form-group col-sm-12">
            <table class="table table-striped table-bordered table-hover text-center">
                <tr>
                    <td>
                        <div class="form-group-sm text-center">
                            消费信息
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group col-sm-12">
                            <table class="table table-striped table-bordered table-hover text-center">
                                <thead>
                                <tr>
                                    <th>商品编码</th>
                                    <th>商品名称</th>
                                    <th>数量</th>
                                    <th>销售单价</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="spxxdd">

                                </tbody>
                            </table>
                        </div>
                    </td>
                </tr>
            </table>
            <%--            <!-- 右边中部的盒子结束 -->--%>
        </div>
        <%--        <!-- 右边下部的盒子 -->--%>
        <div class="form-group col-sm-12">
            <table id="dingdanquan" class="table table-striped table-bordered table-hover text-center">
                <tr>
                    <td class="col-sm-3">
                        <div class="form-group">
                            订单编号
                        </div>
                    </td>
                    <td class="col-sm-3 dingdan"></td>
                    <td class="col-sm-3">
                        <div class="form-group">
                            消费时间
                        </div>
                    </td>
                    <td class="col-sm-3 dingdan"></td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group">
                            消费数量
                        </div>
                    </td>
                    <td class="dingdan"></td>
                    <td>
                        <div class="form-group">
                            消费总金额
                        </div>
                    </td>
                    <td class="dingdan"></td>
                </tr>
                <tr>
                    <td colspan="4">
                        <input type="button" class="btn btn-success btn-sm" onclick="tijiao()" value="提交订单"/>
                    </td>
                </tr>
            </table>
            <%--            <!-- 右边下部的盒子结束 -->--%>
        </div>
        <%--        <!-- 右边盒子结束 -->--%>
    </div>
    <%--    <!-- 全局盒子结束 -->--%>
</div>
<%--<!-- 会员详情模态框开始 -->--%>
<div class="modal focus" id="hyxq">
    <div class="modal-dialog modal-content modal-lg">
        <%--        <!--模态框头部-->--%>
        <div class="modal-header">
            <button class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">会员信息列表</h4>
        </div>
        <%--        <!--模态框内容-->--%>
        <div class="modal-body">
            <div class="form-group">
                <table class="table table-striped table-hover table-bordered text-center">
                    <thead>
                    <tr class="info">
                        <th>会员卡号</th>
                        <th>持卡人姓名</th>
                        <th>会员ID</th>
                        <th>会员等级</th>
                        <th>卡余额</th>
                        <th>卡积分</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody id="hytb">
                    </tbody>
                </table>
            </div>
        </div>
        <div class="modal-footer">
            <%--            <!--模态框下边-->--%>
            <div class="form-inline">
                <div class="form-group pull-left" id="xinxizs">
                    <div class="form-inline">
                        <label>显示第<span id="rowstarthy"></span>到第<span id="rowendhy"></span>条记录,总共
                            <span id="rowcounthy"></span>条记录,每页显示</label>
                        <select class="form-control" id="pageSizehy">
                            <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="20">20</option>
                            <option value="50">50</option>
                            <option value="100">100</option>
                        </select>
                        <label>条记录</label>
                    </div>
                </div>
                <div class="form-group pull-right">
                    <div class="btn-group text-right">
                        <a href="javascript:searchhy(pageBeanhy.pageNo-1)" class="btn btn-default"><</a>
                        <div id="btnhy" class="btn-group"></div>
                        <a href="javascript:searchhy(pageBeanhy.pageNo+1)" class="btn btn-default">></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%--    <!-- 会员详情模态框结束 -->--%>
</div>
<%--<!-- 提交订单模态框开始 -->--%>
<div id="tjdd" class="modal focus" data-backdrop="static">
    <div class="modal-dialog modal-content modal-lg ">
        <%--        <!--模态框头部-->--%>
        <div class="modal-header">
            <button class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">会员信息列表</h4>
        </div>
        <div class="modal-body">
            <!--模态框内容-->
            <table class="table table-hover table-bordered table-striped text-center">
                <tr>
                    <td>订单列表</td>
                </tr>
                <tr>
                    <td>
                        <table class="table table-hover table-bordered table-striped text-center">
                            <tr>
                                <td class="col-sm-2">订单编号</td>
                                <td class="col-sm-6 xfddtj"><span></span></td>
                                <td class="col-sm-2">消费数量</td>
                                <td class="col-sm-2 xfddtj"><span></span></td>
                            </tr>
                            <tr>
                                <td>应付金额</td>
                                <td class="xfddtj"></td>
                                <td>账户余额</td>
                                <td class="xfddtj"></td>
                            </tr>
                            <tr>
                                <td>实付金额</td>
                                <td>
                                    <input type="text" class="form-control xfddtj" disabled="disabled"
                                           disabled="disabled"/>
                                </td>
                                <td >找零金额</td>
                                <td class="xfddtj"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="input-group">
                            <label class="input-group-addon">备注</label>
                            <textarea class="form-control" id="momo" placeholder="备注"></textarea>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="modal-footer">
            <input type="button" class="btn btn-success btn-sm" onclick="jiesuan()" value="结算"/>
        </div>
    </div>
</div>
<!-- 提交订单模态框结束-->
</body>


<%--  商品数据显示	--%>
<script type="text/javascript">
    //success info warning error
    let pageBean = new Object();
    pageBean.pageNo = 1;
    pageBean.pageSize = 4;
    pageBean.factor = [];

    let pageBeanhy = new Object();
    pageBeanhy.pageNo = 1;
    pageBeanhy.pageSize = 5;

    function searchhy(num) {
        //判断上一页有没有
        if (num > 0) {
            pageBeanhy.pageNo = num;
        } else {
            pageBeanhy.pageNo = 1;
            num = 1;
        }
        //判断下一页有没有
        if (num <= pageBeanhy.totalPage) {
            pageBeanhy.pageNo = num;
        } else {
            if (pageBeanhy.totalPage != 0) {
                pageBeanhy.pageNo = pageBeanhy.totalPage;
            } else {
                pageBeanhy.pageNo = 1;
            }
        }
        pageBeanhy.data = "";
        showhy();
    }

    //界面开始时候的显示数据
    function showhy() {
        $.ajax({
            url: "${pageContext.request.contextPath}/commodityController/showhy",
            data: pageBeanhy,
            success: function (date) {
                pageBeanhy = date;
                pageBeanhy.factor = [];
                $('#rowcounthy').html(pageBeanhy.rowCount);
                $('#rowstarthy').html(pageBeanhy.rowCount == 0 ? 0 : pageBeanhy.startIndex + 1);
                let con = pageBeanhy.rowCount == 0 ? 0 :
                    pageBeanhy.pageNo == pageBeanhy.totalPage ?
                        pageBeanhy.rowCount % pageBeanhy.pageSize == 0 ?
                            pageBeanhy.pageSize : pageBeanhy.rowCount % pageBeanhy.pageSize
                        : pageBeanhy.pageSize;
                $('#rowendhy').html(pageBeanhy.startIndex + con);
                let btns = "";
                for (let i = 0; i < pageBeanhy.totalPage; i++) {
                    if (pageBeanhy.pageNo == i + 1) {
                        btns += "<a href='javascript:searchhy(" + (i + 1) + ");' class='btn btn-primary'>" + (i + 1) + "</a>";
                    } else {
                        btns += "<a href='javascript:searchhy(" + (i + 1) + ");' class='btn btn-default'>" + (i + 1) + "</a>";
                    }
                }
                $('#btnhy').html(btns);
                //表格显示
                let tr = "";
                let cards = pageBeanhy.data;
                if (cards != null) {
                    for (let i = 0; i < cards.length; i++) {
                        let status = "";
                        let user = cards[i]['user'];
                        let userName = "";
                        let userId = "";
                        if (user != null) {
                            userName = user['userName'];
                            userId = user['userId'];
                        }
                        if (cards[i]['status'] == 1) {
                            status = "<button class='btn btn-info btn-xs'>启用</button>";
                        } else {
                            status = "<button class='btn btn-danger btn-xs'>禁用</button>";
                        }
                        tr += "<tr ondblclick='addhy()'>" +
                            "<td>" + cards[i]['cardId'] + "</td>\n" +
                            "<td>" + userName + "</td>\n" +
                            "<td>" + userId + "</td>\n" +
                            "<td>" + cards[i]['cardtype']['name'] + "</td>\n" +
                            "<td>" + parseFloat(cards[i]['amount']).toFixed(2) + "</td>\n" +
                            "<td>" + cards[i]['credit'] + "</td>\n" +
                            "<td>" + status + "</td>" +
                            "</tr>"
                    }
                }
                $('#hytb').html(tr);
            },
            dataType: "json"
        });

    }

    function search(num) {
        //判断上一页有没有
        if (num > 0) {
            pageBean.pageNo = num;
        } else {
            pageBean.pageNo = 1;
            num = 1;
        }
        //判断下一页有没有
        if (num <= pageBean.totalPage) {
            pageBean.pageNo = num;
        } else {
            if (pageBean.totalPage != 0) {
                pageBean.pageNo = pageBean.totalPage;
            } else {
                pageBean.pageNo = 1;
            }
        }
        //判断员工编号填写没有
        if ($('#shopid').val() != "") {

            if ($('#shopid').val().indexOf("'") >= 0) {
                pageBean.factor.push(" 1=0 ");
            } else {
                pageBean.factor.push(" goodsId like '%" + $('#shopid').val() + "%' ");
            }
        }
        //判断员工姓名填写没有
        if ($('#shopname').val() != "") {
            if ($('#shopname').val().indexOf("'") >= 0) {
                pageBean.factor.push(" 1=0 ");
            } else {
                pageBean.factor.push(" name like '%" + $('#shopname').val() + "%' ");
            }
        }
        pageBean.data = "";
        show();
    }

    //界面开始时候的显示数据
    function show() {
        $.ajax({
            url: "${pageContext.request.contextPath}/commodityController/show",
            data: pageBean,
            success: function (date) {
                pageBean = date;
                pageBean.factor = [];
                $('#rowcountsp').html(pageBean.rowCount);
                $('#rowstartsp').html(pageBean.rowCount == 0 ? 0 : pageBean.startIndex + 1);
                let con = pageBean.rowCount == 0 ? 0 :
                    pageBean.pageNo == pageBean.totalPage ?
                        pageBean.rowCount % pageBean.pageSize == 0 ?
                            pageBean.pageSize : pageBean.rowCount % pageBean.pageSize
                        : pageBean.pageSize;
                $('#rowendsp').html(pageBean.startIndex + con);
                let btns = "";
                for (let i = 0; i < pageBean.totalPage; i++) {
                    if (pageBean.pageNo == i + 1) {
                        btns += "<a href='javascript:search(" + (i + 1) + ");' class='btn btn-primary'>" + (i + 1) + "</a>";
                    } else {
                        btns += "<a href='javascript:search(" + (i + 1) + ");' class='btn btn-default'>" + (i + 1) + "</a>";
                    }
                }
                $('#btnsp').html(btns);
                //表格显示
                let tr = "";
                if (pageBean.data != null) {
                    for (let i = 0; i < pageBean.data.length; i++) {
                        tr += "<tr ondblclick='addshop()'>" +
                            "<td>" + pageBean.data[i]["goodsId"] + "</td>" +
                            "<td>" + pageBean.data[i]["name"] + "</td>" +
                            "<td>" + pageBean.data[i]["code"] + "</td>" +
                            "<td>" + pageBean.data[i]["unit"]["name"] + "</td>" +
                            "<td>" + pageBean.data[i]["category"]["name"] + "</td>" +
                            "<td>" + pageBean.data[i]["price"] + "</td>" +
                            "</tr>"
                    }
                }
                $('#sptb').html(tr);
            },
            dataType: "json"
        });

    }

    //读卡按钮的实现
    function duka() {
        let huiyId = $('#huiId').val();
        if (huiyId != "") {
            let idtest = /^\d{6}$/;
            if (idtest.test(huiyId)) {
                dukaajax(huiyId);
            } else {
                toastr.warning('请输入正确会员卡ID');
            }
        } else {
            //info success error warning
            toastr.warning('请输入会员卡ID');
        }
    }


    //重置按钮的实现
    function chongzhi() {
        event.target.parentNode.parentNode.firstElementChild.firstElementChild.value = '';
        $('#hyxxquan .xyxx').each(function () {
            this.innerHTML = '';
        })

    }

    //订单数量以及订单总金额的变化
    function dingdan() {
        let now = new Date().format("yyyy-MM-dd hh:mm:ss");
        let sum = 0;
        let money = 0;
        //	let now=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
        $('#spxxdd tr').each(function () {
            let i = parseInt(this.getElementsByTagName('td')[2].innerHTML);
            let j = parseFloat(this.getElementsByTagName('td')[3].innerHTML);
            sum += i;
            money += i * j;
        })
        let tds = $('#dingdanquan').get(0).getElementsByClassName('dingdan');
        tds[1].innerHTML = now;
        tds[2].innerHTML = sum;
        tds[3].innerHTML = money.toFixed(2);
    }

    //删除商品订单
    function shanchu() {
        event.target.parentNode.parentNode.remove();
        dingdan();
    }

    //点击结算
    function jiesuan() {
        let tds = $('#tjdd .xfddtj');
        let tbs = $('#dingdanquan .dingdan');
        let hyxx = $('#hyxxquan .xyxx');
        let cardId = hyxx[2].innerHTML;
        let orderId = tds[0].innerHTML;
        let createdTime = tbs[1].innerHTML;
        let price = parseFloat(tbs[3].innerHTML).toFixed(2);
        let momo = $('#momo').val();
        let goodsId = [];
        let goodsName = [];
        let goodsNum = [];
        let goodsPrice = [];
        $('#spxxdd tr').each(function () {
            goodsId.push(this.getElementsByTagName("td")[0].innerHTML);
            goodsName.push(this.getElementsByTagName("td")[1].innerHTML);
            goodsNum.push(this.getElementsByTagName("td")[2].innerHTML);
            goodsPrice.push(this.getElementsByTagName("td")[3].innerHTML);
        });
        if (parseInt(tds[5].innerHTML) >= 0 || parseInt(hyxx[3].innerHTML) - parseInt(tds[2].innerHTML) >= 0) {
            $.ajax({
                url: "/commodityController/addOrder",
                type: "post",
                data: {
                    cardId: cardId,
                    orderId: orderId,
                    createdTime: createdTime,
                    price: price,
                    goodsId: goodsId,
                    goodsName: goodsName,
                    goodsNum: goodsNum,
                    goodsPrice: goodsPrice,
                    momo: momo
                },
                success: function (data) {
                    if (data == 2) {
                        toastr.warning('会员卡余额不足,请充值');
                    }else if (data == 0) {
                        toastr.error('消费失败');
                    } else {
                        if (data != 1) {
                            dukaajax(data,0);
                            $('#spxxdd').html("");
                        }
                        toastr.success('消费成功');
                    }
                    $("#tjdd").modal("hide");
                    $('#spxxdd').html("");
                    $('.dingdan').each(function () {
                        this.innerHTML="";
                    })
                    dingdanId();
                    search(pageBean.pageNo);
                },
                dataType: "json"
            });
        } else {
            toastr.error('您的金额不足');
        }
    }

    //点击提交订单按钮
    function tijiao() {
        let tds = $('#tjdd .xfddtj');
        let tbs = $('#dingdanquan .dingdan');
        let money = $('#hyxxquan .xyxx').get(3).innerHTML;
        if (tbs[3].innerHTML == "") {
            toastr.info('请购买商品');
        } else {
            $("#tjdd").modal("show");
            if (money == '') {
                toastr.info('您正处于游客模式');
                tds[0].innerHTML = tbs[0].innerHTML;
                tds[1].innerHTML = tbs[2].innerHTML;
                tds[2].innerHTML = tbs[3].innerHTML;
                tds[3].innerHTML = "";
                tds[4].disabled = "";
                tds[5].innerHTML = "";
                tds[4].onblur = function () {
                    tds[5].innerHTML = parseFloat(isNaN(parseFloat(tds[4].value).toFixed(2) - parseFloat(tds[2].innerHTML).toFixed(2)) ? 0 : parseFloat(tds[4].value) - parseFloat(tds[2].innerHTML)).toFixed(2);
                }
            } else {
                toastr.success('您正处于刷卡模式');
                let disCount = 1.00;
                $.post(
                    "/commodityController/disCount",
                    {cardtypeName: $('.xyxx').get(4).innerHTML},
                    function (data) {
                        disCount = parseFloat(data).toFixed(2);
                        tds[0].innerHTML = tbs[0].innerHTML;
                        tds[1].innerHTML = tbs[2].innerHTML;
                        tds[2].innerHTML = tbs[3].innerHTML;
                        tds[3].innerHTML = money;
                        tds[4].value = "";
                        tds[4].disabled = "disabled";
                        tds[5].innerHTML = 0 - (parseFloat(tds[2].innerHTML) * parseFloat(disCount)).toFixed(2);
                    }, "json"
                );
            }
        }
    }

    //从商品信息中往消费信息中添加商品数据
    function addshop() {
        let tr = event.target.parentNode;
        let tbs = tr.getElementsByTagName('td');
        let pd = true;
        if(parseInt(tbs[2].innerHTML)==0){
            toastr.warning("此商品库存数量不足");
        }else{
            $('#spxxdd tr').each(function () {
                let tid = this.getElementsByTagName('td')[0].innerHTML;
                if (tid == tbs[0].innerHTML) {
                    let num = this.getElementsByTagName('td')[2];
                    if (parseInt(num.innerHTML) < parseInt(tbs[2].innerHTML)) {
                        num.innerHTML = parseInt(num.innerHTML) + 1;
                    } else {
                        toastr.warning("此商品库存数量不足");
                    }
                    pd = false;
                }
            })
            if (pd) {
                $('#spxxdd').append('<tr><td>' + tbs[0].innerHTML + '</td>' +
                    '<td>' + tbs[1].innerHTML + '</td>' +
                    '<td>' + 1 + '</td><td>' + tbs[5].innerHTML + '</td>' +
                    '<td><input type="button" class="btn btn-danger btn-sm" onclick="shanchu()" value="删除" /></td>' +
                    '</tr>');

            }
            dingdan();
        }
    }

    //会员详情中点击数据添加到会员信息中
    function addhy() {
        let tbs = event.target.parentNode.getElementsByTagName('td');
        if (tbs[tbs.length - 1].innerHTML == '<button class="btn btn-info btn-xs">启用</button>') {
            let tds = $('#hyxxquan .xyxx');
            tds[0].innerHTML = tbs[2].innerHTML;
            tds[1].innerHTML = tbs[1].innerHTML;
            tds[2].innerHTML = tbs[0].innerHTML;
            tds[3].innerHTML = parseFloat(tbs[4].innerHTML).toFixed(2);
            tds[4].innerHTML = tbs[3].innerHTML;
            tds[5].innerHTML = tbs[5].innerHTML;
            toastr.success('读卡成功');
        } else {
            toastr.error('此会员卡已被禁用');
        }
        $('#hyxq').modal('hide');
    }

    //订单编号查询
    function dingdanId() {
        let ddid = $('#dingdanquan').get(0).getElementsByClassName('dingdan')[0];
        $.ajax({
            url: "${pageContext.request.contextPath}/commodityController/findByDdId",
            type: "post",
            success: function (data) {
                $('#dingdanquan').get(0).getElementsByClassName('dingdan')[0].innerHTML = data;
            },
            dataType: "json"
        });
    }

    //
    function dukaajax(huiyId,flag) {
        $.ajax({
            url: "${pageContext.request.contextPath}/commodityController/findByhyId",
            type: "post",
            async:false,
            data: {cardId: huiyId},
            success: function (data) {
                if (data != null) {
                    if (data['status'] == 1) {
                        if(flag!=0){
                            toastr.success('读卡成功');
                        }
                        let tds = $('#hyxxquan .xyxx');
                        tds[0].innerHTML = data['userId'];
                        tds[1].innerHTML = data['user']['userName'];
                        tds[2].innerHTML = data['cardId'];
                        tds[3].innerHTML = parseFloat(data['amount']).toFixed(2);
                        tds[4].innerHTML = data['cardtype']['name'];
                        tds[5].innerHTML = data['credit'];
                    } else {
                        toastr.error('此会员卡已被禁用');
                    }
                } else {
                    toastr.warning('没有找到会员卡ID对应的会员卡');
                }
            },
            dataType: "json"
        })
    };

    $(function () {
        dingdanId();
        search(1);
        searchhy(1);
        $('#pageSize').on('change', function () {
            pageBean.pageSize = parseInt($('#pageSize').val());
            search(1);
        });
        $('#pageSizehy').on('change', function () {
            pageBeanhy.pageSize = parseInt($('#pageSizehy').val());
            searchhy(1);
        });
        $('#shoubtn').click(function () {
            search(1);
        });
        $('#tjdd').on('show.bs.modal',function () {
            $(this).clea();
        })
    })
</script>
</html>